各リソース・マネージャは、xa.h
ヘッダー・ファイルにスイッチを定義します。ヘッダー・ファイルによって、トランザクション・マネージャはリソース・マネージャ内のXA関数にアクセスできます。トランザクション・マネージャでは、XAインタフェース関数を直接コールしません。かわりに、スイッチ表の関数をコールします。スイッチ表は、リソース・マネージャ内の該当する関数を指します。これによって、アプリケーションを再コンパイルしなくても、リソース・マネージャを追加および削除できます。
TimesTenでのXAの実装では、XAスイッチxa_switch_tの関数は、tt_xa_switchというTimesTenスイッチで定義されているそれぞれの関数を指します。
XA標準によって定義されているxa_switch_t
構造は次のとおりです。
/*
* XA Switch Data Structure
*/
#define RMNAMESZ 32 /* length of resource manager name, */
/* including the null terminator */
#define MAXINFOSIZE 256 /* maximum size in bytes of xa_info strings, */
/* including the null terminator */
struct xa_switch_t
{
char name[RMNAMESZ]; /* name of resource manager */
long flags; /* resource manager specific options */
long version; /* must be 0 */
int (*xa_open_entry)(char *, int, long); /* xa_open function pointer */
int (*xa_close_entry)(char *, int, long); /* xa_close function pointer*/
int (*xa_start_entry)(XID *, int, long); /* xa_start function pointer */
int (*xa_end_entry)(XID *, int, long); /* xa_end function pointer */
int (*xa_rollback_entry)(XID *, int, long); /* xa_rollback function pointer */
int (*xa_prepare_entry)(XID *, int, long); /* xa_prepare function pointer */
int (*xa_commit_entry)(XID *, int, long); /* xa_commit function pointer */
int (*xa_recover_entry)(XID *, long, int, long); /* xa_recover function pointer*/
int (*xa_forget_entry)(XID *, int, long); /* xa_forget function pointer */
int (*xa_complete_entry)(int *, int *, int, long);/* xa_complete function pointer */
};
typedef struct xa_switch_t xa_switch_t;
/*
* Flag definitions for the RM switch
*/
#define TMNOFLAGS 0x00000000L /* no resource manager features selected */
#define TMREGISTER 0x00000001L /* resource manager dynamically registers */
#define TMNOMIGRATE 0x00000002L /* RM does not support association migration */
#define TMUSEASYNC 0x00000004L /* RM supports asynchronous operations */
tt_xa_switchでは、TimesTenリソース・マネージャで実装されている実際の関数に名前を付けます。また、関連移行がサポートされていないことを明示的に示しており、動的な登録と非同期の処理がサポートされていないことを省略することで示しています。
struct xa_switch_t
tt_xa_switch =
{
"TimesTen", /* name of resource manager */
TMNOMIGRATE, /* RM does not support association migration */
0,
tt_xa_open,
tt_xa_close,
tt_xa_start,
tt_xa_end,
tt_xa_rollback,
tt_xa_prepare,
tt_xa_commit,
tt_xa_recover,
tt_xa_forget,
tt_xa_complete
};